﻿@model YCMS.Models.MemberListViewModel

@{
    ViewBag.Title = "Member List";
    PagedList.PagedList<YCMS.Domain.Entities.Member> members = (PagedList.PagedList<YCMS.Domain.Entities.Member>)Model.Members;

}

<h2>Member List</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            @Html.ActionLink("LastName", "List", new {sortOrder = ViewBag.MemberNameSortOrder})
        </th>
        <th>
           @Html.ActionLink("MemberNumber", "List", new {sortOrder = ViewBag.MemberNumberSortOrder})
        </th>
        <th>
            FirstName
        </th>
        <th></th>
    </tr>

@foreach (var item in Model.Members) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.LastName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.MemberNumber)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.FirstName)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.ID, SortOrder = Model.SortOrder, page = Model.PageNumber }) |
            @Html.ActionLink("Details", "Details", new { id=item.ID, SortOrder = Model.SortOrder, page = Model.PageNumber }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ID })
        </td>
    </tr>
}



</table>
<div> <!--Display Paging controls -->
    Page @(members.PageCount < members.PageNumber ? 0 : members.PageNumber) of @members.PageCount
    &nbsp
    @if (members.HasPreviousPage)
    {
        @Html.ActionLink("<<", "List", new { page = 1, sortOrder = ViewBag.CurrentSort })
        @Html.Raw("&nbsp")
        @Html.ActionLink("< Prev", "List", new { page = members.PageNumber - 1, sortOrder = ViewBag.CurrentSort })
    }
    else
    {
        @:<<
        @Html.Raw("&nbsp")
        @:< Prev
    }
    &nbsp
    @if (members.HasNextPage)
    {
        @Html.ActionLink("Next >", "List", new { page = members.PageNumber + 1, sortOrder = ViewBag.CurrentSort })
        @Html.Raw("&nbsp")
        @Html.ActionLink(">>", "List", new { page = members.PageCount, sortOrder = ViewBag.CurrentSort })
    }
    else
    {
        @:Next >
        @Html.Raw("&nbsp")
        @:>>
    }
</div>